<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>目录管理</title>
<%@ include file="/module/js.jsp"%>
</head>
<body>
	<form action="#" name="Form" id="Form" method="post">
		<input type="hidden" name="idList" id="idList"/>
	    <input type="hidden" id="bodyData" name="bodyData" value=""/>
	<%@ include file="/module/orderField.jsp"%>
		<table cellpadding="1" cellspacing="1" border="0">
			<tr>
				<td><input type="button" id="btnQuery" value="查询"
					class="inputButton" /></td>
			
					
			   <c:if test="${xmlevel==0}">
			     <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"OF_ZLTS_CLGL\")%>" key="add">	
					<td><input type="button" id="btnAdd" value="添 加 "
						class="inputButton" /></td>
						</kl:permission>
						  <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"OF_ZLTS_CLGL\")%>" key="delete">	
					<td><input type="button" id="btnDelete" value="删 除"
						 class="inputButton"/></td>
						 </kl:permission>
		      </c:if>			 
		
			</tr>
		</table>
		
		
		 <table cellpadding="1" cellspacing="1">
			<tr>
				<td>目录名称：</td>
				<td><input type="text" name="directoryName" id="directoryName"   autocomplete="off" class="inputText" /></td>
			</tr>
		</table>	
		<table id="dg"  style="width:100%;"
		data-options="pagination:true,collapsible:true,url:'${basePath}/directory/List',method:'post',remoteSort:true,striped:true">
		<thead>
			<tr>
		     	<th data-options="field:'directoryId',checkbox:true,width:80,align:'left'"></th>
		     	<th data-options="field:'id',sortable:true,nowrap:true,width:60,align:'left',hidden: true">项目id</th>
			    <th data-options="field:'projectName',sortable:true,nowrap:true,width:300,align:'left'">项目名称</th>
				<th data-options="field:'directoryName',sortable:true,nowrap:true,width:300,align:'left',formatter: formater">目录名称</th>
			    <th data-options="field:'xm',sortable:true,nowrap:true,width:200,align:'left'">负责人</th>
			    <th data-options="field:'name',nowrap:true,width:300,align:'left',sortable:true">创建人</th>
			    <th data-options="field:'addDate',nowrap:true,width:300,align:'left',sortable:true,formatter:formatDate">添加时间</th>
			    <th data-options="field:'cz',nowrap:true,width:150,align:'left',sortable:true,formatter:formlogo">操作</th> 
			</tr>
		</thead>
	</table>
		
		
</form>
		

		 <script type="text/javascript">
		 
		  function formatDate(value){
		    	var date=new Date(value);
				var y = date.getFullYear();
				var m = date.getMonth()+ 1;
				var d = date.getDate();
				var h= date.getHours();       //获取当前小时数(0-23)
				var mm= date.getMinutes();     //获取当前分钟数(0-59)
				var s= date.getSeconds();     //获取当前秒数(0-59)
				return y +'-'+(m <10?('0'+ m):m)+'-'+(d <10?('0'+ d):d)+' :'+(h <10?('0'+ h):h)+':'+(mm <10?('0'+ mm):mm)+':'+(s <10?('0'+ s):s);
			}
	    
			  function formater(value, row, index) {
				  if("${xmlevel}"==0){
				         return "<a href='${basePath}/directory/details?id=" + row.directoryId + "'>" + value + "</a>";
	              }else{
	            	  return  value;
				   }
			  }
			
			
			  function formlogo(value,row, index){
				      if(row.mllogo>=1){
					      return "<a href='${basePath}/projectmaterial/index?directoryId=" + row.directoryId +"&projectId="+row.id+"&level="+row.level+"'>" + '<input type="button" id="btnAddProjectmaterial" value="上传材料"  class="inputButton"/>' + "</a>";
				      }else{
				    	  return "";
				      }
			  }  
		 
			$(document).ready(function() {
	                             $('#dg').datagrid({
								  /*  onSortColumn :function(sort,order){
								   var _sort=sort;
								   var _order=order;
								   var options=$('#dg').datagrid('getPager').data("pagination").options;
								   var page=options.pageNumber;
								   var pageSize=options.pageSize;
								   window.setTimeout(function(){
									   $.post("${basePath}/directory/List",{orderFlag:_order,orderField:_sort,
										   directoryName: $('#directoryName').val()},
												function(data){
												  $('#dg').datagrid("loadData",data); 
											   });
											   },100);  
								   }, */
								   
								   onClickRow: function (rowIndex, rowData) {
						                 $(this).datagrid('unselectRow', rowIndex);
						            },
						            
						            
								   onLoadSuccess: function(data){//加载完毕后获取所有的checkbox遍历
									                 if (data.rows.length > 0) {
									                    //循环判断操作为新增的不能选择
									                    var checkbox = $("input[type='checkbox']");
									                    for (var i = 0; i < data.rows.length; i++) {
									                        //根据operate让某些行不可选
									                        if (data.rows[i].mllogo2 != 1) {
										                                 $(checkbox.get(i+1)).remove();
										                            	//$("input[type='checkbox']")[i+1].remove();
										                               // $('#dg').datagrid('deleteRow',i);//选择该行 
									                                  // $("input[type='checkbox']")[i + 1].disabled = true;
									                                  //$("input[type='checkbox']")[i].remove();
									                        }
									                    }
									                }
								   },
								   
								   rowStyler: function(index,row){
								   },
								  
								  
								   
								});
								//返回
								/* 	$('#btnBreak').click(function() {
										  window.location.href = "${basePath}/project/index";
									}); */
								
								$('#btnAdd').click(function() {
									   window.location.href = "${basePath}/directory/addInInt";
								});
								
									
							   $('#easyui-ck').click(function() {
								    var data = $("#dg").datagrid("getSelections");
				                    for (var i = 0; i < data.length; i++) {
				                        //根据states让某些行不可选
				                        if (data[i].mllogo2 != 1) {
					                            	//$("input[type='checkbox']")[i+1].remove();
					                                 $('#dg').datagrid('unselectRow',i);//选择该行 
					                                 $("#easyui-ck").attr('checked','checked'); 
				                                     // $("input[type='checkbox']")[i + 1].disabled = true;
				                        }
				                    }
								}); 		
									
								
								//查询
								$('#btnQuery')
										.click(
												function() {
													$('#dg').datagrid('load',{
														directoryName: $('#directoryName').val()
													});
												});
								
								$('#btnDelete').click(function() {
									    $("#idList").val("");
													
												    var count = 0;
													var idList = new Array();
												    var sels = $("#dg").datagrid("getSelections");
											    	for(var i in sels){
											    		idList.push(sels[i].directoryId);
											    		count++;
											    	}
													if (count == 0) {
														layer.alert("您至少选择一条删除记录信息", {icon: 3});
														return false;
													}else{
														  layer.confirm("您是否删除当前选中数据信息", {icon: 3, title:'提示',skin:'layer-ext-moon'}, function(index){
															    $("#idList").val(idList);
															    document.Form.action = "${basePath}/directory/delete";
																document.Form.submit();
														  },function(index){
																layer.close(index);
														  });
													}
												});
						     	});
			
			
			
						$('#btnUpdate').click(function() {
									    var count = 0;
										var directoryId =null;
									    var sels = $("#dg").datagrid("getSelections");
								    	for(var i in sels){
								    		if (count == 1) {
												  layer.alert("只能允许选择一条编辑记录信息", {icon: 3});
												  return false;
											}
								    		directoryId=sels[i].directoryId;
								    		count++;
								    	}
										if (count == 0) {
											 layer.alert("请选择一条编辑记录信息", {icon: 3});
											 return false;
										}else{
											window.location.href = "${basePath}/directory/details?id="+directoryId;
										}
						  });
			
			
			  if("${msg}"!=""){
			       layer.alert("${msg}", {icon: 6});
			 } 
		</script>
</body>
</html>
